var CompanyMaterialTypeForm = function () {
  var template = /*html*/ `
    <div class="companyMaterialTypeForm" v-loading="loading">
      <el-form class="material-form" :model="companyMaterialType" label-width="140px">
        <el-form-item label="物料类型">
          <el-input class="form-input" v-if="type!=='update'" v-model="companyMaterialType.materialType"></el-input>
          <span v-else>{{companyMaterialType.materialType}}</span>
        </el-form-item>
       <!-- <el-form-item label="是否读取颜色">
          <el-select class="form-input" v-if="companyMaterialType.isSelfAdded ===1 || type==='add'" v-model="companyMaterialType.isReadColor">
            <el-option
              v-for="item in readColorList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select> 
          <span v-else>{{companyMaterialType.isReadColor===1?'读取':'不读取'}}</span>
        </el-form-item> -->
        <el-form-item label="仓位">
          <el-select class="form-input" v-if="companyMaterialType.isSelfAdded ===1 || type==='add'" v-model="companyMaterialType.defaultWarehouse">
            <el-option
              v-for="item in defaultWarehouseList"
              :key="item.value"
              :label="item.label" 
              :value="item.value">
            </el-option>
          </el-select> 
          <span v-else>{{companyMaterialType.defaultWarehouse===1?'原材料仓':companyMaterialType.defaultWarehouse===2?'辅料仓':'信息备注仓'}}</span>
        </el-form-item>
        <el-form-item label="状态">
          <el-select class="form-input" v-if="companyMaterialType.isSelfAdded ===1 || type==='add'" v-model="companyMaterialType.status">
            <el-option
              v-for="item in statusList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select> 
          <span v-else>{{companyMaterialType.status===0?'禁用':'使用'}}</span>
        </el-form-item>
        <el-form-item label="制单页面是否显示">
          <el-select class="form-input" v-if="companyMaterialType.isSelfAdded ===1 || type==='add'" v-model="companyMaterialType.createOrderIsShow">
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="2"></el-option>
          </el-select> 
          <span v-else>{{companyMaterialType.createOrderIsShow===1?'是':'否'}}</span>
        </el-form-item>
        <el-form-item label="创建人" v-if="type==='update'">
          <span>{{companyMaterialType.createUser}}</span>
        </el-form-item>
        <el-form-item label="创建时间" v-if="type==='update'">
          <span>{{companyMaterialType.createTime}}</span>
        </el-form-item>
        <el-form-item label="最后一次修改人" v-if="type==='update'">
          <span>{{companyMaterialType.lastModifier}}</span>
        </el-form-item>
        <el-form-item label="最后一次修改时间" v-if="type==='update'">
          <span>{{companyMaterialType.lastModifiedTime}}</span>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-if="type==='update' && companyMaterialType.id !=='' && companyMaterialType.isSelfAdded !== 2" @click="updateCompanyMaterialType">修改</el-button>
          <el-button type="primary" v-if="type==='add'" @click="addCompanyMaterialType">保存</el-button>
        </el-form-item>
      </el-form>
    </div>
  `;
  return {
    props: {
      companyMaterialType: {
        type: Object,
        required: true
      },
      type: {
        type: String,
        default: 'add'
      }
    },
    data: function () {
      return {
        loading: false,
        readColorList: [{
          label: '读取',
          value: 1
        }, {
          label: '不读取',
          value: 2
        }],
        statusList: [{
          label: '禁用',
          value: 0
        }, {
          label: '使用',
          value: 1
        }],
        defaultWarehouseList: [{
            label: '原材料仓',
            value: 1
        }, {
            label: '辅料仓',
            value: 2
        }, {
            label: '信息备注仓',
            value: 3
        }]
      }
    },
    methods: {
      //修改物料类型配置表
      updateCompanyMaterialType: function () {
        var companyMaterialType = this.companyMaterialType;
        if (!companyMaterialType.checkValid()) {
          return;
        }
        var postData = companyMaterialType.getObject();
        this.loading = true;
        var self = this;
        ajaxRequest("companyMaterialType/updateCompanyMaterialType", postData).then(function (data) {
          self.$alert(data, '信息');
          self.$emit('update');
          self.loading = false;
        }).catch(function (error) {
          console.log(error);
          self.loading = false;
        });
      },
      //新增物料类型配置表
      addCompanyMaterialType: function () {
        var companyMaterialType = this.companyMaterialType;
        if (!companyMaterialType.checkValid()) {
          return;
        }
        var postData = companyMaterialType.getObject();
        if(postData.materialType.indexOf("|")>-1 || postData.materialType.indexOf("all")>-1){
        	this.$alert("物料类型不能有特殊符号或all","信息");
        	return;
        }
        this.loading = true;
        var self = this;
        ajaxRequest("companyMaterialType/addCompanyMaterialType", postData).then(function (data) {
          self.$alert(data, '信息');
          self.$emit('add');
          self.loading = false;
        }).catch(function (error) {
          console.log(error);
          self.loading = false;
        });
      }
    },
    template: template
  }
}();